package org.rooster.manager;

import org.rooster.dbmanager.repository.RoosterRepository;
import org.rooster.schedule.ResourcePreference;

import java.util.Iterator;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 7/22/12
 * Time: 9:21 AM
 * To change this template use File | Settings | File Templates.
 */
public class ResourcePreferencesTracker {

    private static ResourcePreferencesTracker instance;
    //todo clearly state the following definition regarding employee preference
    //array values [employeeId-1][section no-1] = employee's preference for this section (in 1-5 range)
    //if employee's preference is high then he likes to work in that section more than other sections
    private int[][] employeePreferenceArray;

    private ResourcePreferencesTracker() {
        employeePreferenceArray = new int[ResourceManager.TOTAL_NO_OF_EMPLOYEES][TaskManager.NO_OF_SECTIONS];
        initializeEmployeePreferences();
    }

    public static ResourcePreferencesTracker getInstance() {
        if (instance == null) {
            instance = new ResourcePreferencesTracker();
        }
        return instance;
    }

    private void initializeEmployeePreferences() {
        Set<ResourcePreference> managerPreferenceSet = RoosterRepository.getInstance().retrieveResourcePreferencesSet();

        //todo retrieve the number of tasks using the count SQl statements

        Iterator iterator = managerPreferenceSet.iterator();
        ResourcePreference employeePreference;
        while (iterator.hasNext()) {
            employeePreference = (ResourcePreference) iterator.next();
            employeePreferenceArray[employeePreference.getResourceId() - 1][employeePreference.getTaskId()] = employeePreference.getPreference();
        }
    }

    public int getEmployeePreferences(int employeeId, int sectionNo) {
        return employeePreferenceArray[employeeId - 1][sectionNo - 1];
    }
}
